package com.fx.zmlzml.controller;

import com.fx.zmlzml.common.response.Result;
import com.fx.zmlzml.domain.dto.AhpPcComponentPriceWeightDTO;
import com.fx.zmlzml.domain.vo.PcVO;
import com.fx.zmlzml.entity.AhpPcComponentPriceWeight;
import com.fx.zmlzml.service.AhpPcComponentPriceWeightService;
import com.fx.zmlzml.service.PcService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;
import java.util.Random;

/**
 * 测试控制器，用于验证Swagger文档功能
 */
@RestController
@RequestMapping("/api/pc")
@Tag(name = "组装PC主接口", description = "提供组装PC的相关接口")
public class PcController {

    @Autowired
    private PcService pcService;

    @Autowired
    private AhpPcComponentPriceWeightService ahpPcComponentPriceWeightService;

    /**
     * 获取电脑配件价格权重列表
     * @return 电脑配件价格权重列表
     */
    @GetMapping("/priceWeights")
    @Operation(summary = "priceWeights", description = "获取电脑配件价格权重列表")
    public Result<List<AhpPcComponentPriceWeight>> getPriceWeights() {
        return Result.i18nSuccess(ahpPcComponentPriceWeightService.getAll(), "pc.priceWeights.success", null);
    }

    /**
     * 测试接口 - 获取欢迎信息
     * @return 欢迎信息
     */
    @CrossOrigin("*")
    @PostMapping("/ai_pc")
    @Operation(summary = "ai_pc", description = "AI生成组装PC")
    public Result<List<PcVO>> aiPc(@RequestBody @Parameter(description = "预算价格") AhpPcComponentPriceWeightDTO ahpPcComponentPriceWeightDTO) {
        List<PcVO> pcVOList = new ArrayList<>();
        PcVO pcVO = new PcVO();
        pcVO.setPcMotherboard("主板");
        pcVO.setPcCpu("CPU");
        pcVO.setPcCooler("散热器");
        pcVO.setPcGpu("显卡");
        pcVO.setPcMemory("内存");
        pcVO.setPcHardDisk("硬盘");
        pcVO.setPcPowerSupply("电源");
        pcVO.setPcCase("机箱");
        int random = new Random().nextInt(10);
        for (int i = 0; i < random; i++) {
            pcVOList.add(pcVO);
        }
        return Result.i18nSuccess(pcVOList, "pc.query.success", null);
    }

    /**
     * 测试接口 - 获取欢迎信息
     * @return 欢迎信息
     */
    @CrossOrigin("*")
    @PostMapping("/ai_pc_test")
    @Operation(summary = "ai_pc_test", description = "AI生成组装PC")
    public Result<List<PcVO>> aiPcTest(@Valid @RequestBody @Parameter(description = "预算价格") AhpPcComponentPriceWeightDTO ahpPcComponentPriceWeightDTO) {
        return Result.i18nSuccess(pcService.getAiPcListByPrice(ahpPcComponentPriceWeightDTO), "cpu.query.success", null);
    }

}